var app = getApp();
Page({
    data:{
        siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
        showall : false,
        sharedata : {},
		reports : [
            '色情、暴力、赌博',
            '敏感信息',
            '民族、宗教歧视',
            '空镜头挂机',
            '引导用户线下交易',
            '出售危险品、违禁品',
            '其他',
        ],
        reason : '',
        reportIndex : -1,
        checkItem : '',
        pics : [],
        id : 0,
    },
    onLoad:function(options){
        var self = this;
        var id = options.id ? options.id : '';
        self.data.id = id;

        app.com.http('live','POST',{op:'reportinfo',liveid:id},0,false,'','',function(res){
            if (!res.data.errno && res.data) {
                self.setData({
                    params : res.data.data.params,
                    sharedata : res.data.data.sharedata,
                    inited : true,
                });

            }else{
                app.com.alert(res.data.message,function(){
                    app.com.backPage(0);
                });
            }
        });
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.sharedata.title,
            path: self.data.sharedata.path,
            imageUrl : self.data.sharedata.img,
        }
    },
    afterRead(e){
        var self = this;
        wx.showLoading({mask:true,title:'上传中'});
        wx.uploadFile({
            url: app.siteInfo.siteroot+'?i='+app.siteInfo.uniacid+'&j=&c=utility&a=file&do=upload&type=image&thumb=0',
            filePath: e.detail.file.path,
            name: 'file',
            success: function(res){
                var aaa = JSON.parse( res.data );
                self.data.pics.push({
                    url : aaa.url,
                    img : aaa.attachment
                })
                self.setData({
                    pics : self.data.pics,
                })
            },
            complete : function(){
                wx.hideLoading();
            },
            fail : function(rr){
                console.log(rr)
            }
        })
    },
    sub(){
        var self = this;
        var postdata = {
            op:'subreport',
            checkItem : this.data.checkItem,
            reason : this.data.reason,
            liveid : this.data.id,
            img :   JSON.stringify( self.data.pics )
        }

        app.com.http('live','POST',postdata,0,true,'','',function(res){
            if (!res.data.errno) {
                app.com.toast(res.data.message,'success',function(){
                    wx.navigateBack();
                });
            }else{
                app.com.toast( res.data.message,'none' );
            }
        });
    },
    changetype(e){
        this.setData({
            reportIndex : e.currentTarget.dataset.i,
            checkItem : this.data.reports[e.currentTarget.dataset.i],
        })
    },
    input(e){
        this.setData({
            reason : e.detail.value
        })
    },
    back(e){
        app.com.backPage(0);
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e);
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    }
    
})